package com.youngjun.user.controller.admin;

import com.youngjun.common.mybatis.web.BaseController;
import com.youngjun.common.mybatis.web.Response;
import com.youngjun.user.api.admin.IUserRestApi;
import com.youngjun.user.pojo.dto.UserDTO;
import com.youngjun.user.pojo.dto.query.UserQueryDTO;
import com.youngjun.user.pojo.vo.UserVO;
import com.youngjun.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@RestController
@RequestMapping("/user")
public class UserController implements IUserRestApi,BaseController {

    @Autowired
    UserService userService;

    @Override
    public Response<List<UserVO>> queryListByCurrentOrganization(@RequestBody UserQueryDTO dto) {
        List<UserVO> data = userService.queryListByCurrentOrganization(dto);
        return new Response<>(data);
    }

    @Override
    public Response<UserVO> createByCurrentOrganization(@RequestBody UserDTO dto) {
        UserVO data = userService.createByCurrentOrganization(dto);
        return new Response<>(data);
    }

    @Override
    public Response<UserVO> modifyByCurrentOrganization(@RequestBody UserDTO dto) {
        UserVO data = userService.modifyByCurrentOrganization(dto);
        return new Response<>(data);
    }

    @Override
    public Response<Void> deleteByCurrentOrganization(@RequestParam Long id){
        userService.deleteByCurrentOrganization(id);
        return new Response<>();
    }

    @Override
    public Response<List<UserVO>> queryList(@RequestBody UserQueryDTO dto){
        List<UserVO> data = userService.queryList(dto);
        return new Response<>(data);
    }

    @Override
    public Response<UserVO> create(@RequestBody @Valid UserDTO dto){
        UserVO data = userService.create(dto);
        return new Response<>(data);
    }

    @Override
    public Response<UserVO>  modify(@RequestBody @Valid UserDTO dto){
        UserVO data = userService.modify(dto);
        return new Response<>(data);
    }

    @Override
    public Response<Void> delete(@RequestParam Long id){
        userService.delete(id);
        return new Response<>();
    }
}